package idv.kikka.server.handler;

import idv.kikka.server.service.factories.SessionServiceFactory;
import idv.kikka.common.message.PingMessage;
import idv.kikka.server.service.SessionService;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;

@ChannelHandler.Sharable
@Slf4j
public class PingMessageHandler extends SimpleChannelInboundHandler<PingMessage> {
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, PingMessage msg) throws Exception {
        SessionService sessionService= SessionServiceFactory.getSessionService();
        String username = sessionService.getUsername(ctx.channel());
        if(username!=null){
            //        ctx.channel().writeAndFlush(new PongMessage(username+"接收到心跳，一切正常"));
        }
        else {
            //        ctx.channel().writeAndFlush(new PongMessage(ctx.channel()+"接收到心跳，一切正常"));
        }//客户端需要额外处理PongMessage
    }
}
